﻿using System.Collections.Generic;
using System.IO;
public static class GlobalMembers
{
	public static SortedDictionary<string, InstanceKlass > allClass = new SortedDictionary<string, InstanceKlass >();



	/**
	 * 初始化本地方法
	 */
	public static SortedDictionary<string, CODENATIVE> map = new SortedDictionary<string, CODENATIVE>();
	//
	// Created by Arosy on 2022/1/2.
	//

	//
	// Created by Arosy on 2022/1/2.
	//
	// #ifndef JVM_INSTANCEOOP_H
	// #define JVM_INSTANCEOOP_H

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern class InstanceKlass;



	public static void startVM()
	{
		CodeRunBase.initCodeRun(); //初始化字节码解释器，把解析JVM指令的方法全部存入map,以便使用
		CodeRunNative.initCodeRun(); //初始化本地方法，把本地方法全部存入map,以便使用
	}

	public static int Main(string name)
	{
		startVM();
		//string name = "jvm/HelloJVM";
		JavaThread javaThread = new JavaThread(); //模拟线程的创建
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: Threads::curThread = javaThread;
		Threads.curThread = javaThread;
		InstanceKlass klass = BootClassLoader.loadKlass(name); //加载HelloJVM类
		MethodInfo m = JavaNativeInterface.getMethod(klass, "main", "([Ljava/lang/String;)V"); //遍历klass所有的方法，找到main方法
		JavaNativeInterface.callStaticMethod(javaThread, m); //执行main方法
		return 0;
	}
	//using namespace std;
	//public static void startVM()
	//{
	//	Console.Write("test");
	//	Console.Write("\n");
	//}
}

public class FILE
{
    public FileStream stream;
    public FILE(FileStream stream)
    {
        this.stream = stream;
    }
}

public class FileC
{
    public static SeekOrigin SEEK_END= SeekOrigin.End;
    public static FILE fopen(string path,string mode)
    {
        FILE file =new FILE( File.Open(path,FileMode.Open));
        return file;
    }
    public static long fseek(FILE file,int offset, SeekOrigin seekOrigin)
    {
      return  file.stream.Seek(offset, seekOrigin);
    }

    public static int fread(byte[] array, FILE file, int offset,int count)
    {
        return file.stream.Read(array,offset, count);
    }

    public static int ftell(FILE file)
    {
        return (int)file.stream.Length;
    }

    public static ushort htons(ushort v)
    {
        return v;
    }

    public static uint htonl(uint v)
    {
        return v;
    }

    public static int htonl(int v)
    {
        return v;
    }
}

public static class Unit
{
    public static string append(this string s, string ss)
    {
        s += ss;
        return s;
    }
}